package com.fly.studio.home.app.arrange.base;

import com.fly.studio.home.app.component.BaseContext;
import com.jd.platform.async.callback.ICallback;
import com.jd.platform.async.callback.IWorker;
import com.jd.platform.async.worker.WorkResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Base Worker
 *
 * @author fuliying3
 * @date 2022/08/23 09:07:00
 */
public interface BaseWorker extends IWorker<BaseContext, BaseContext>, ICallback<BaseContext, BaseContext> {

    Logger log = LoggerFactory.getLogger(BaseWorker.class);

    /**
     * 调用action之前调用-callback方法
     */
    @Override
    default void begin() {
        Thread thread = Thread.currentThread();
        Class<? extends BaseWorker> clazz = this.getClass();
        log.info("BaseWorker begin currentFloor -> {}, currentThread -> {}", clazz.getSimpleName(), thread.getName());
    }

    /**
     * 调用action之后执行-callback方法
     *
     * @param b          是否成功
     * @param context    {@link BaseContext}
     * @param workResult {@link WorkResult}
     */
    @Override
    default void result(boolean b, BaseContext context, WorkResult<BaseContext> workResult) {
        Thread thread = Thread.currentThread();
        Class<? extends BaseWorker> clazz = this.getClass();
        log.info("{} Callback currentThread -> {} result b -> {}", clazz.getSimpleName(), thread.getName(), b);
    }

}
